package com.kafka.producer.mainstay;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xuhaifeng
 * @since 2022年02月18日 下午 10:41
 */
@Slf4j
@RestController
@RequestMapping
public class ProducerRoute {
    private final KafkaTemplate<String, Object> kafka;

    @Autowired
    public ProducerRoute(KafkaTemplate<String, Object> kafka) {this.kafka = kafka;}

    @GetMapping("/info")
    public Object info() {
        final JSONObject info = new JSONObject();
        info.put("firstRow", "11");
        info.put("lastRow", "22");
        info.put("firstCol", "33");
        info.put("lastCol", "44");
        info.put("content", "爬山的煎熬收盘价");
        // IdUtil.fastSimpleUUID()
        kafka.send("lattice", String.valueOf(info.toJSONString().hashCode()), info.toJSONString());
        return "yes";
    }

}
